package com.wu.Service.ServiceImpl;


import com.wu.DO.teacherDO;
import com.wu.Dao.GraduateMapper;
import com.wu.Dao.TeacherMapper;
import com.wu.Service.TeacherService;
import com.wu.Util.MD5Util;
import com.wu.common.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by admin on 2018/11/26.
 */
@Service
public class TeacherServiceImpl implements TeacherService {
    @Autowired
    TeacherMapper teacherMapper;
    @Autowired
    GraduateMapper graduateMapper;
    @Override
    public ServerResponse<teacherDO> login(String username, String password) {
        int usercheck = teacherMapper.checkUserName(username);
        if (usercheck == 0) {
            return ServerResponse.createByErrorMessage("用户名不存在");
        }
        String MD5password = MD5Util.MD5EncodeUtf8(password);
        teacherDO student = teacherMapper.login(username, password);
        if (student == null) {
            return ServerResponse.createByErrorMessage("用户密码不正确");
        }
        return ServerResponse.createBySuccess("登录成功",student);
    }

    @Override
    public ServerResponse<String> addGraduate(Integer projectId, String title, String introduction, String tname, Integer teacherId) {
       int count= graduateMapper.addGraduate(projectId,title,introduction,tname,teacherId);
        if(count==0){
            return ServerResponse.createByErrorMessage("添加课题未成功");
        }
        return ServerResponse.createBySuccess("成功添加一个课题");
    }
}
